#include "mytool.h"
#include "QDebug"

mytool::mytool()
{

}



unsigned char mytool::cal_crc8(QByteArray &dat,int length)
{
    unsigned int sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += (uint8_t)dat[i];
    }
   //  qDebug()<<sum;
    return  (unsigned char)(sum);
}





unsigned char mytool::APP_FrameCMD_Strip(QByteArray &INBuff, uint8_t in_length_bytes,QByteArray &OUTBuff)
{
   unsigned int  seek_cnt=0;
   unsigned int  i=0;

     while(seek_cnt<in_length_bytes)
     {
        if(INBuff.at(seek_cnt)=='\xfe')
        {
            seek_cnt++;
        }
        else if(INBuff.at(seek_cnt)==0x68)
        {

            if(INBuff.at(seek_cnt+1)!='\xfe')
            {
                for(i=0; i<(in_length_bytes-seek_cnt); i++)
                {
                    OUTBuff.data()[i] =  INBuff.at(i+seek_cnt);

                }
                break;

            }
       }
       else
       {
           seek_cnt++;

       }

     }
     return (in_length_bytes-seek_cnt);
}



